//
//  LeaderBoardVC.m
//  XiJianChui
//
//  Created by Mac on 16/7/20.
//  Copyright © 2016年 FanShuHan. All rights reserved.
//

#import "LeaderBoardVC.h"
#import "LeaderBoardTableViewCell.h"
#import "StylistViewController.h"

static NSString *leaderBoardCellID = @"leaderBoardCellID";
@interface LeaderBoardVC ()

@property(nonatomic,weak) UIButton *levelBtn;
@property(nonatomic,weak) UIButton *popularityBtn;

@end

@implementation LeaderBoardVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.backgroundColor = QhColor(239, 239, 244);
    self.title = @"排行榜";
    //注册cell
    [self.tableView registerNib:[UINib nibWithNibName:@"LeaderBoardTableViewCell" bundle:nil] forCellReuseIdentifier:leaderBoardCellID];
    
    [self setupTopView];
    
}

//添加顶部条
- (void)setupTopView {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, QhScreenW, 40)];
//    view.backgroundColor = [UIColor redColor];
    //添加两个按钮
    UIButton *levelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    levelBtn.frame = CGRectMake(100, 7, 60, 40);
    levelBtn.selected = YES;
    [levelBtn setTitle:@"等级" forState:UIControlStateNormal];
    [levelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [levelBtn setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
    [levelBtn addTarget:self action:@selector(levelBtnClick) forControlEvents:UIControlEventTouchUpInside];
    self.levelBtn = levelBtn;
    [view addSubview:levelBtn];
    
    UIButton *popularityBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    popularityBtn.frame = CGRectMake(QhScreenW - 160, 7, 60, 40);
    [popularityBtn setTitle:@"人气" forState:UIControlStateNormal];
    [popularityBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [popularityBtn setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
    [popularityBtn addTarget:self action:@selector(popularityBtnClick) forControlEvents:UIControlEventTouchUpInside];
    self.popularityBtn = popularityBtn;
    [view addSubview:popularityBtn];
    
    self.tableView.tableHeaderView = view;
}

//按钮点击方法实现
- (void)levelBtnClick {
    self.levelBtn.selected = YES;
    self.popularityBtn.selected = NO;
}

- (void)popularityBtnClick {
    self.popularityBtn.selected = YES;
    self.levelBtn.selected = NO;
}

#pragma mark - UITableViewDataSource&&UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 5;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:leaderBoardCellID];
    if (cell == nil) {
        cell = [[LeaderBoardTableViewCell alloc] init];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 150;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    NSLog(@"%s",__func__);
    StylistViewController *vc = [[StylistViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
}


@end
